package com.shujia.jdbc;

import java.sql.*;

public class Demo1Jdbc {

    public static void main(String[] args) {


        //1、加载驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


        //2、创建连接
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://master:3306/student", "root", "123456");


            //3、查询数据
            PreparedStatement stat = con.prepareStatement("select * from student");

            //4、执行拆线呢
            ResultSet resultSet = stat.executeQuery();


            //如果有下一个就取下一个
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                int age = resultSet.getInt("age");
                String gender = resultSet.getString("gender");
                String clazz = resultSet.getString("clazz");


                System.out.println(id + '\t' + name + "\t" + age + '\t' + gender + "\t" + clazz);

            }


            //关闭连接
            con.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
